package be.sc.classicnetwork.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import be.sc.classicnetwork.service.CarService;

/**
 * Aspect around CarServiceImpl.
 */
@Aspect
public class CarServiceImplAspect {

	private CarService carService;

	/**
	 * Checks the user is not anonymous to see unpublished cars.
	 */
	@Around("execution(* be.sc.classicnetwork.service.impl.CarServiceImpl.findByIdFull(..)) && args(id)")
	public Object findByIdFull(ProceedingJoinPoint joinPoint, String id)
			throws Throwable {
		// // get the car
		// Car car = this.carService.findById(id);
		//
		// // get current user
		// User currentUser = User.getCurrentUser();
		//
		// // anonymous user cannot see unpublished car
		// if ((car != null)
		// && ((currentUser == User.ANONYMOUS_USER) && !car.isPublished())) {
		// // send to FORBIDDEN page (403)
		// throw new ForbiddenException("User forbidden: "
		// + currentUser.getUsername());
		// }

		// normal case
		return joinPoint.proceed();
	}

	public void setCarService(CarService carService) {
		this.carService = carService;
	}

}
